﻿<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>会员管理
            <small>会员档案</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>会员管理</el-breadcrumb-item>
            <el-breadcrumb-item>会员档案</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号" v-model="queryData.queryString_fileNumber" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-input placeholder="姓名" v-model="queryData.queryString_name" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-input placeholder="手机号" v-model="queryData.queryString_phone" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPageByConditions()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleUpdate()">新建</el-button>
                <el-button @click="del()" type="danger">删除</el-button>
            </div>
            <el-table
                    ref="multipleTable"
                    tooltip-effect="dark"
                    style="width: 100%"
                    @selection-change="handleSelectionChange"
                    :data="dataList">
                <el-table-column
                        type="selection"
                        width="55">
                </el-table-column>
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column label="性别" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="phoneNumber" label="手机号" align="center"></el-table-column>
                <el-table-column prop="h_name" label="健康管理师" align="center"></el-table-column>
                <el-table-column prop="regTime" label="注册时间" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog :title="title" :visible.sync="dialogFormVisible4Edit">
                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <template slot-scope="scope">
                            <el-tabs v-model="activeName" type="card">
                                <el-tab-pane label="基本信息" name="first">
                                    <el-form label-position="right" label-width="100px" ref="addForm" :rules="rules">
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="姓名" prop="name">
                                                    <el-input v-model="formData.name"/>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="手机号" prop="phoneNumber">
                                                    <el-input v-model="formData.phoneNumber"/>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="性别">
                                                    <el-select v-model="sex">
                                                        <el-option label="男" value="1"></el-option>
                                                        <el-option label="女" value="2"></el-option>
                                                    </el-select>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="身份证号" prop="idCard">
                                                    <el-input v-model="formData.idCard"></el-input>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="邮箱">
                                                    <el-input v-model="formData.email"></el-input>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="健康管理师" prop="h_name">
                                                    <el-select v-model="formData.h_name" placeholder="请选择">
                                                        <el-option
                                                                v-for="item in options"
                                                                :key="item.id"
                                                                :label="item.label"
                                                                :value="item.name">
                                                        </el-option>
                                                    </el-select>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="注意事项">
                                                    <el-input v-model="formData.remark" type="textarea"></el-input>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                    </el-form>
                                </el-tab-pane>
                            </el-tabs>
                        </template>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {
            sex:"1",
            options: [],
            title: '',//标签栏名称
            // pageFlag: 0,//判断是否是第一次带查询条件查询
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100
            },
            queryData: {//查询条件
                queryString_fileNumber: null,
                queryString_name: null,
                queryString_phone: null
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                phoneNumber: [{required: true, message: '手机号为必填项', trigger: 'blur'}],
                name: [{required: true, message: '姓名为必填项', trigger: 'blur'}],
                h_name:[{required: true, message: '请选择一个健康管理师', trigger: 'blur' }],
                idCard:[{required: true, message: '请填写身份证号', trigger: 'blur' }]
            },
            multipleSelection: [],
            ids: []
        },
        created() {
            this.findPage();
        },
        methods: {
            handleEdit() {
                this.$refs['dataEditForm'].validate((valid) => {
                    alert(valid);
                    this.dialogFormVisible4Edit = false;
                    if (valid) {
                        alert("提交！");
                        axios.post("/member/edit.do", this.formData).then((res) => {
                            if (res.data.flag) {
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                })
                            } else {
                                this.$message.error(res.data.message);
                            }
                        }).finally(() => {
                            this.findPage();
                        })
                    }else{
                        alert("没提交");
                        return false;
                    }
                })
            },
            findPageByConditions() {
                /**
                 * 这个是解决分页查询 带条件 查询结果的当前页不是第一页
                 * 解决办法 只有当点击查询按钮的时候 将当前页置为1
                 */
                this.pagination.currentPage = 1;
                this.findPage();
            },
            //分页查询
            findPage() {
                let param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryData: this.queryData
                };

                axios.post("/member/findByPage.do", param).then((res) => {
                    this.dataList = res.data.rows;
                    this.pagination.total = res.data.total
                })

            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                if (row != null) {
                    this.title = "编辑会员";

                } else {
                    this.title = "新增会员";
                }
                axios.get("/member/findAllHealthManager.do").then((response) => {
                    this.options = response.data.data;
                })

                this.dialogFormVisible4Edit = true;
                if (row != null) {
                    axios.get("/member/findById.do?id=" + row.id).then((res) => {
                        this.formData = res.data.data;
                    })
                } else {
                    this.formData = {};
                }
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            //批量删除
            del() {
                if (this.multipleSelection == undefined || this.multipleSelection.length <= 0) {
                    this.$message.error("请选择删除对象!");
                } else {
                    this.$confirm('确认删除？').then(_ => {
                        if (this.multipleSelection != null) {
                            this.multipleSelection.forEach(row => {
                                this.ids.push(row.id);
                            })
                        }
                        this.handleDelete();
                    })
                }
            },
            // 删除
            handleDelete(row) {
                if (row != null) {
                    this.ids.push(row.id);
                    this.$confirm('确认删除？')
                        .then(_ => {
                            axios.get("/member/delete.do?id=" + this.ids).then((res) => {
                                if (res.data.flag) {
                                    this.$message({
                                        message: res.data.message,
                                        type: 'success'
                                    });
                                    this.ids = [];
                                } else {
                                    this.$message.error(res.data.message);
                                    this.ids = [];
                                }
                            }).catch(_ => {
                            }).finally(() => {
                                this.findPage();
                            });
                        })
                } else {
                    axios.get("/member/delete.do?id=" + this.ids).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                            this.ids = [];
                        } else {
                            this.$message.error(res.data.message);
                            this.ids = [];
                        }
                    }).catch(_ => {
                    }).finally(() => {
                        this.findPage();
                    });
                }
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    })
</script>
</html>
